import torch
import torchtext
import time


class VecEmbedder():

    def __init__(self):
        super(VecEmbedder, self).__init__()
        self.glove_embedding = torchtext.vocab.GloVe(name='6B', dim=100)
        self.embedding_dim = 100

    def embed(self, sentence: str):
        # print(sentence)
        sens = sentence.split(' ')
        vecs = self.glove_embedding.get_vecs_by_tokens(sens, lower_case_backup=True)
        return vecs


if __name__ == '__main__':
    model = VecEmbedder()
    s = '环境监测数据认可的申请'
    start = time.time()
    for i in range(1):
        vs = model.embed(s)
        print(vs)
    end = time.time()
    print(end - start)